home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_33872.txt < prev    next >
Text File  |  1991-02-27  |  951b  |  28 lines

  1. -- card: 33872 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. Functions may call themselves in a RECURSIVE fashion.  For example, a function to raise a floating-point number to an integral power may be written:
  11.  
  12.     float  expon(float  x, int y)
  13.     {
  14.         if (y>0)
  15.             return x * expon(x,y-1);
  16.         else
  17.             return 1.;
  18.     }
  19.  
  20. The scope of the formal parameters (and local variables, if any) of a function is the body of the function, and separate values for these variables are maintained for each invocation of the function.  Thus there is no conflict when passing the value y-1 as an argument to the expon() function, even though the identifier y is itself used as a parameter of the called function.
  21.  
  22. -- part contents for background part 7
  23. ----- text -----
  24. 97
  25.  
  26. -- part contents for background part 6
  27. ----- text -----
  28. 3.5  Recursion